package com.kerwin.event;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class Isolate {

    //微任务队列-优先级高 5
    public static Queue<ScheduleMicrotask> scheduleMicrotasks = new LinkedBlockingQueue<>();
    //事件队列-优先级低 8
    public static Queue<Timer> eventQueue = new LinkedBlockingQueue<>();

    public static void processAsync(){

        //总共要执行13次
        //每次一个
        //在有scheduleMicrotasks情况下有限执行scheduleMicrotasks
        //没有scheduleMicrotasks才执行timer
        while(!scheduleMicrotasks.isEmpty() || !eventQueue.isEmpty()){
            Task task = null;
            task = scheduleMicrotasks.poll();
            task = task == null ? eventQueue.poll() : task;
            task.run();
        }
    }


    void main(){
        Main.main(null);
        processAsync();
    }
}
